package com.gimi.cloud.bbp.app.consumer.service.home.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.gimi.cloud.bbp.app.consumer.feign.HomePageFeignService;
import com.gimi.cloud.bbp.app.consumer.service.home.HomePageService;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.dto.base.BaseDTO;
import com.gimi.cloud.bbp.dto.mall.MallAppSpecialDTO;
import com.gimi.cloud.bbp.dto.mall.MallAppSpecialGroupDTO;
import com.gimi.cloud.bbp.dto.page.PageConfigDTO;

/**
 * Created by shazhiwei on 2017/12/27.
 */
@Service
public class HomePageServiceImpl implements HomePageService {
    @Autowired private HomePageFeignService homePageFeignService;

    @Override
    public void columnList(String requestBody, HttpServletRequest request, HttpServletResponse response) throws Exception {
        BaseDTO params = JsonUtil.jsonToBean(requestBody,BaseDTO.class);
        Util.sendResponse(homePageFeignService.columnList(params), response);
    }

    @Override
    public void adList(String requestBody, HttpServletRequest request, HttpServletResponse response) throws Exception {
        BaseDTO params = JsonUtil.jsonToBean(requestBody,BaseDTO.class);
        Util.sendResponse(homePageFeignService.adList(params), response);
    }

	@Override
	public void getHomePageCarouselFigure(String requestData, HttpServletRequest request,
			HttpServletResponse response) {
		BaseDTO parseObject = JSON.parseObject(requestData, BaseDTO.class);
		Util.sendResponse(homePageFeignService.getHomePageCarouselFigure(parseObject), response);
	}

	@Override
	public void getPage(String requestBody, HttpServletRequest request, HttpServletResponse response) throws Exception {
		PageConfigDTO params = JsonUtil.jsonToBean(requestBody, PageConfigDTO.class);
        Util.sendResponse(homePageFeignService.getPage(params), response);
	}

	@Override
	public void getHomePageData(String requestData, HttpServletRequest request, HttpServletResponse response) {
		BaseDTO parseObject = JSON.parseObject(requestData, BaseDTO.class);
		Util.sendResponse(homePageFeignService.getHomePageData(parseObject), response);
	}
	
	@Override
	public void getIndex(String requestData, HttpServletRequest request, HttpServletResponse response) {
		MallAppSpecialGroupDTO dto = JSON.parseObject(requestData, MallAppSpecialGroupDTO.class);
		Util.sendResponse(homePageFeignService.getIndex(dto), response);
	}

	@Override
	public void getSpecialList(String requestData, HttpServletRequest request, HttpServletResponse response) {
		MallAppSpecialDTO dto = JSON.parseObject(requestData, MallAppSpecialDTO.class);
		if (dto.getAsgId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		Util.sendResponse(homePageFeignService.getSpecialList(dto), response);
	}

}
